home *** CD-ROM | disk | FTP | other *** search
- Path: news.uh.edu!bti!usenet
- From: "Sean C. Olson" <olson@rose.rsoc.rockwell.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Templates & friends
- Date: Tue, 16 Apr 1996 15:09:32 -0500
- Organization: Rockwell Space Operations
- Message-ID: <3173FE7C.7B2@rose.rsoc.rockwell.com>
- References: <317211BF.41C6@sonytel.be>
- NNTP-Posting-Host: rose.rsoc.rockwell.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.01 (X11; I; SunOS 5.4 sun4m)
-
- Philip Rademakers wrote:
- >
- > Hi,
- >
- > Does anybody know how to declare a friend class that is one of the
- > argument classes? I tried the following:
- >
- > class X {
- > protected:
- > X();
- > };
- >
- > template<class T>
- > class foo {
- > private:
- > T* _ptr;
- > public:
- > friend class T;
- > foo() { _ptr = new T; }
- > };
- >
-
- Try instead:
-
- template <class T> class foo;
-
- template <class T> class X {
- friend class foo<T>;
-
- protected:
- X();
- };
-
- template <class T> class foo {
- private:
- T* _ptr;
- public:
- foo () { _ptr = new T; }
- };
-
- Basically, the class template foo must be declared a friend of the
- class X. But since foo is a parameterized type, you will want X to be as
- well for the friend declaration. (I think)
-
- --
- Sean Olson (713) 282-3740
- Unisys Space Systems olson@rose.rsoc.rockwell.com
- RSOC
-